let POINT_STYLE = {
  Angle: 0,
  Color: 6, //子图的颜色
  Space: 0,
  SymHeight: 5, //子图的高度
  SymID: 21, //子图号
  SymWidth: 5, //子图的宽度
}
/* Java（3每天2个小时） */
class Point {
  static add({ position, attr, service, docLayer }) {
    /* 1、设置点要素 */
    /* 几何 */
    var gpoint = new Zondy.Object.GPoint(position[0], position[1])
    var fGeom = new Zondy.Object.FeatureGeometry({ PntGeom: [gpoint] })
    /* 样式 */
    if (attr[1].value == '刮擦' || attr[0].value <= 1) {
      POINT_STYLE.Color = 7
    }
    if (
      attr[1].value == '翻车' ||
      attr[1].value == '碾压' ||
      attr[0].value >= 4
    ) {
      POINT_STYLE.Color = 4
    }
    var pointInfo = new Zondy.Object.CPointInfo(POINT_STYLE)
    var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
      // type:1(Point)|2(Line)|3(Area)
      InfoType: 1,
      PntInfo: pointInfo,
    })
    /* 属性 */
    /* 1-3、属性信息 */
    var attValue = attr.map((item) => item.value)
    // 构建点要素
    //创建一个要素
    var feature = new Zondy.Object.Feature({
      fGeom: fGeom,
      GraphicInfo: webGraphicInfo,
      AttValue: attValue,
    })
    //设置要素为点要素 1|2|3
    feature.setFType(1)
    /* 2、设置[要素集]添加要素 */
    var featureSet = new Zondy.Object.FeatureSet()
    //设置属性结构
    var cAttStruct = new Zondy.Object.CAttStruct({
      FldName: attr.map((item) => item.key),
      FldNumber: attr.length,
      FldType: attr.map((item) => item.type),
    })
    featureSet.AttStruct = cAttStruct
    //添加要素到要素数据集
    featureSet.addFeature(feature)
    /* 3、调用中地服务添加要素 */
    //创建一个编辑服务类
    /* 
    第一个参数是地图文档的名称
    第二个参数是要素所在的图层
     */
    var editService = new Zondy.Service.EditDocFeature(
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163',
      }
    )
    //执行添加点要素功能
    editService.add(featureSet, this.onAddSuccess(docLayer), this.onError)
  }
  static query({ position, service, onSuccess }) {
    var queryStruct = new Zondy.Service.QueryFeatureStruct()
    queryStruct.IncludeGeometry = true
    queryStruct.IncludeWebGraphic = true
    //2、创建一个用于查询的点形状
    var pointObj = new Zondy.Object.Point2D(position[0], position[1])
    //设置点容差半径
    pointObj.nearDis = 1
    //指定查询规则
    var rule = new Zondy.Service.QueryFeatureRule({
      //是否将要素的可见性计算在内
      EnableDisplayCondition: false,
      //是否完全包含
      MustInside: false,
      //是否仅比较要素的外包矩形
      CompareRectOnly: false,
      //是否相交
      Intersect: true,
    })
    //3、实例化查询参数对象
    var queryParam = new Zondy.Service.QueryParameter({
      geometry: pointObj,
      resultFormat: 'json',
      struct: queryStruct,
      rule: rule,
    })
    //4、实例化地图文档查询服务对象
    var queryService = new Zondy.Service.QueryDocFeature(
      queryParam,
      service.docName,
      service.layerId,
      {
        ip: 'localhost',
        port: '6163', //访问IGServer的端口号，.net版为6163，Java版为8089
      }
    )
    //执行查询操作，querySuccess为查询回调函数
    queryService.query(onSuccess)
  }
  static onError(e) {
    console.log(e)
  }
  static onAddSuccess(docLayer) {
    return function (data) {
      console.log('完成后回调', data)
      if (data.succeed) {
        alert('添加点要素成功！')
        docLayer.value.refresh()
      } else {
        alert('添加点要素失败！')
      }
    }
  }
}
export { Point }
